package com.imooc.security.demo.pojo;

import com.fasterxml.jackson.annotation.JsonView;
import com.imooc.security.demo.annotation.MyConstraint;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import javax.validation.constraints.*;
import javax.validation.constraints.NotBlank;
import java.util.Date;

/**
 * @author JackYang
 * @description:
 * @create: 2020/6/13 13:34
 */
@ApiModel(description = "用户实体类")
public class User {
    
    //1.使用接口来声明多个视图
    public interface SimpleView{};
    public interface DetailView extends SimpleView{};
    
    @ApiModelProperty(name = "用户名",value = "就是用户的名字",required = true)
    @NotNull
    private String username;
    @ApiModelProperty(name = "密码",value = "密码很重要",required = true)
    @MyConstraint
    private String password;
    
    /**
     * 表示id属性值，约束条件是id属性不能为null且不能为""
     */
    @NotBlank(message = "id不能为空额")
    private String id;
    private Date birthday;
    
    //2.在值对象的get方法上指定视图
    @JsonView(SimpleView.class)
    public String getUsername() {
        return username;
    }
    
    //2.在值对象的get方法上指定视图。因为detailview继承了simpleView，因此不仅会显示这里的password，还会显示username
    @JsonView(DetailView.class)
    
    /**
     * 以下的get方法没绑定视图，因此在controller中的方法使用@JsonView注解时，以下的这些属性值都不会显示
     */
    public String getPassword() {
        return password;
    }
    public String getId() {
        return id;
    }
    
    public Date getBirthday() {
        return birthday;
    }
    
    
    public void setUsername(String username) {
        this.username = username;
    }
    
    @Override
    public String toString() {
        return "User{" +
                "username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", id='" + id + '\'' +
                ", birthday=" + birthday +
                '}';
    }
    
    public void setPassword(String password) {
        this.password = password;
    }
    
    public void setId(String id) {
        this.id = id;
    }
    
    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }
}
